﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CNotebook;
using CNotebook.Sales;

namespace NotebookS2.Sales.Logs
{
    public partial class LOGS_SalesDelivery : Form
    {
        public LOGS_SalesDelivery()
        {
            InitializeComponent();
        }

        public string ConnectionString { get; set; }

        public void PrintPreview()
        {
            if (xtraTabDR.SelectedTabPageIndex == 0)
            {
                gridControlPerDocument.ShowPrintPreview();
            }
            else
            {
                gridControlPerItem.ShowPrintPreview();
            }
        }

        void BindGrid()
        {
            DeliveryManager oManager = new DeliveryManager();
            DataTable dt = new DataTable();

            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();
            dt = oManager.GetDeliveryLogsPerDocument(Convert.ToDateTime(dtFROM.EditValue), Convert.ToDateTime(dtTO.EditValue),
                                                       chkDraft.Checked, chkDelivered.Checked, chkPosted.Checked, chkOpen.Checked, chkClosed.Checked, checkInprocess.Checked);
            oManager.Close();

            gridControlPerDocument.DataSource = dt;
            gridControlPerDocument.Refresh();
        }

        void BindGridPerItem()
        {
            DeliveryManager oManager = new DeliveryManager();
            DataTable dt = new DataTable();

            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();
            dt = oManager.GetDeliveryLogsPerItems(Convert.ToDateTime(dtFROMItem.EditValue), Convert.ToDateTime(dtTOItems.EditValue),
                                                       chkDraftItem.Checked, chkDeliveredItem.Checked, chkPostedItem.Checked, chkOpenItem.Checked, chkClosedItem.Checked, chkInProcessItem.Checked);
            oManager.Close();

            gridControlPerItem.DataSource = dt;
            gridControlPerItem.Refresh();
        }

        private void LOGS_SalesDelivery_Load(object sender, EventArgs e)
        {
            dtFROM.EditValue = System.DateTime.Now;
            dtTO.EditValue = System.DateTime.Now;

            dtFROMItem.EditValue = System.DateTime.Now;
            dtTOItems.EditValue = System.DateTime.Now;
        }

        private void btnPreview_Click(object sender, EventArgs e)
        {
           // DevExpress.XtraSplashScreen.SplashScreenManager.ShowForm(typeof(LF200));
            BindGrid();
            //DevExpress.XtraSplashScreen.SplashScreenManager.CloseForm();
        }

        private void btnRetreiveItem_Click(object sender, EventArgs e)
        {
            //DevExpress.XtraSplashScreen.SplashScreenManager.ShowForm(typeof(LF200));
            BindGridPerItem();
            //DevExpress.XtraSplashScreen.SplashScreenManager.CloseForm();
        }

        private void gridControlPerItem_Click(object sender, EventArgs e)
        {

        }
    }
}
